import { StackActions, useNavigation } from '@react-navigation/native';

import { getCurrentState } from '@/utils';
import { FirebaseEventsUtil } from '@/utils/analytics';

const useHomeHeaderBar = () => {
  const navigation = useNavigation();
  // 点击设置
  const handleClickSetting = () => {
    navigation.dispatch(StackActions.push('Setting'));
  };
  // 点击会员卡
  const handleClickVipCard = () => {
    navigation.navigate('SubscriptionOne');

    // const state = navigation.getState();
    // if (state) {
    //   const name = getCurrentState(state).name;
    //   FirebaseEventsUtil.goto_subscription(name ?? '');
    // }
    // navigation.dispatch(StackActions.push('Subscription'));
  };
  const handleClickReferAndEarn = () => {
    navigation.dispatch(StackActions.push('InviteCode'));
  };
  const handleOpenSearchModal = (categoryCode: string) => {
    navigation.dispatch(
      StackActions.push('Search', {
        categoryCode,
      }),
    );
  };
  return {
    handleClickSetting,
    handleClickVipCard,
    handleClickReferAndEarn,
    handleOpenSearchModal,
  };
};

export default useHomeHeaderBar;
